package com.wangjw.security.realm;

import com.wangjw.framework.helper.DatabaseHelper;
import com.wangjw.security.SecurityConfig;
import com.wangjw.security.password.Md5CredentialsMatcher;
import org.apache.shiro.realm.jdbc.JdbcRealm;

/**
 * 基于 Smart 的 JDBC Realm(需提供相关 security.jdbc.* 配置项)
 *
 * Created by wangjw on 18/6/25.
 */
public class SmartJdbcRealm extends JdbcRealm {

    public SmartJdbcRealm() {
        super.setDataSource(DatabaseHelper.getDataSource());
        super.setAuthenticationQuery(SecurityConfig.getJdbcAuthcQuery());
        super.setUserRolesQuery(SecurityConfig.getJdbcRolesQuery());
        super.setPermissionsQuery(SecurityConfig.getJdbcPermissionsQuery());
        super.setPermissionsLookupEnabled(true);
        super.setCredentialsMatcher(new Md5CredentialsMatcher()); // 使用 MD5 加密算法
    }
}
